package com.fram.controller.api;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fram.bean.api.browsing.request.BrowsingSearchRequest;
import com.fram.bean.sys.PageBean;
import com.fram.bean.sys.ResponseMsg;
import com.fram.common.canstant.ErrCode;
import com.fram.common.exception.ProException;
import com.fram.common.util.PublicMethod;
import com.fram.common.util.apiversion.ApiVersion;
import com.fram.common.util.base.BaseController;
import com.fram.service.api.v1.UserBrowsingService;

/**
 * @作者： 陳曉鬆 @时间： 2020年5月28日 - 上午9:25:15 @description：->
 */
@RestController
@RequestMapping("/api/{version}/auth/browsing")
public class UserBrowsingController extends BaseController {

	private static Logger LOG = LoggerFactory.getLogger(UserBrowsingController.class);

	@Resource(name = "userBrowsingService")
	private UserBrowsingService userBrowsingService;

	/** 浏览记录列表 */
	@ApiVersion(1.0)
	@RequestMapping("list")
	public ResponseMsg list(@RequestBody PageBean<BrowsingSearchRequest> request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			if (request.getParam() == null) {
				request.setParam(new BrowsingSearchRequest());
			}
			request.getParam().setUserId(getApiUserId());
			msg.setData(userBrowsingService.list(request));
		} catch (ProException e) {
			LOG.error("-浏览记录列表出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-浏览记录列表异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
}
